﻿package frEngine.loaders.particleSub.particleInstance
{
    import __AS3__.vec.*;
    import baseEngine.utils.*;
    import flash.geom.*;

    public class BoxParticle extends MeshBase
    {
        private var _width:Number;
        private var _height:Number;
        private var _depth:Number;
        private var _segments:int = 1;

        public function BoxParticle(param1:Number = 10, param2:Number = 10, param3:Number = 10, param4:uint = 1)
        {
            super(0, 8, true, false);
            this._segments = param4;
            this._depth = param3;
            this._height = param2;
            this._width = param1;
            vertexVector = new Vector.<Number>;
            indexVector = new Vector.<uint>;
            this.createPlane(param1, param2, param3 * 0.5, this._segments, "+xy");
            this.createPlane(param1, param2, param3 * 0.5, this._segments, "-xy");
            this.createPlane(param3, param2, param1 * 0.5, this._segments, "+yz");
            this.createPlane(param3, param2, param1 * 0.5, this._segments, "-yz");
            this.createPlane(param1, param3, param2 * 0.5, this._segments, "+xz");
            this.createPlane(param1, param3, param2 * 0.5, this._segments, "-xz");
            this.numVertex = this.vertexVector.length / this.sizePerVertex;
            return;
        }// end function

        private function createPlane(param1:Number, param2:Number, param3:Number, param4:int, param5:String) : void
        {
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Number = NaN;
            var _loc_9:Number = NaN;
            var _loc_10:Number = NaN;
            var _loc_11:Number = NaN;
            var _loc_12:* = new Matrix3D();
            if (param5 == "+xy")
            {
                Matrix3DUtils.setOrientation(_loc_12, new Vector3D(0, 0, -1));
            }
            else if (param5 == "-xy")
            {
                Matrix3DUtils.setOrientation(_loc_12, new Vector3D(0, 0, 1));
            }
            else if (param5 == "+xz")
            {
                Matrix3DUtils.setOrientation(_loc_12, new Vector3D(0, 1, 0));
            }
            else if (param5 == "-xz")
            {
                Matrix3DUtils.setOrientation(_loc_12, new Vector3D(0, -1, 0));
            }
            else if (param5 == "+yz")
            {
                Matrix3DUtils.setOrientation(_loc_12, new Vector3D(1, 0, 0));
            }
            else if (param5 == "-yz")
            {
                Matrix3DUtils.setOrientation(_loc_12, new Vector3D(-1, 0, 0));
            }
            Matrix3DUtils.setScale(_loc_12, param1, param2, 1);
            Matrix3DUtils.translateZ(_loc_12, param3);
            var _loc_13:* = _loc_12.rawData;
            var _loc_14:* = Matrix3DUtils.getDir(_loc_12);
            _loc_6 = vertexVector.length / this.sizePerVertex;
            _loc_7 = _loc_6;
            _loc_9 = 0;
            while (_loc_9 <= param4)
            {
                
                _loc_8 = 0;
                while (_loc_8 <= param4)
                {
                    
                    _loc_10 = _loc_8 / param4 - 0.5;
                    _loc_11 = _loc_9 / param4 - 0.5;
                    vertexVector.push(_loc_10 * _loc_13[0] + _loc_11 * _loc_13[4] + _loc_13[12], _loc_10 * _loc_13[1] + _loc_11 * _loc_13[5] + _loc_13[13], _loc_10 * _loc_13[2] + _loc_11 * _loc_13[6] + _loc_13[14], 1 - _loc_8 / param4, 1 - _loc_9 / param4, _loc_14.x, _loc_14.y, _loc_14.z);
                    _loc_6++;
                    _loc_8 = _loc_8 + 1;
                }
                _loc_9 = _loc_9 + 1;
            }
            _loc_6 = indexVector.length;
            _loc_9 = 0;
            while (_loc_9 < param4)
            {
                
                _loc_8 = 0;
                while (_loc_8 < param4)
                {
                    
                    var _loc_15:* = _loc_6 + 1;
                    indexVector[_loc_15] = (_loc_8 + 1) + _loc_9 * (param4 + 1) + _loc_7;
                    var _loc_16:* = _loc_6 + 1;
                    indexVector[_loc_16] = (_loc_8 + 1) + (_loc_9 + 1) * (param4 + 1) + _loc_7;
                    var _loc_17:* = _loc_6 + 1;
                    indexVector[_loc_17] = _loc_8 + (_loc_9 + 1) * (param4 + 1) + _loc_7;
                    var _loc_18:* = _loc_6 + 1;
                    indexVector[_loc_18] = _loc_8 + _loc_9 * (param4 + 1) + _loc_7;
                    var _loc_19:* = _loc_6 + 1;
                    indexVector[_loc_19] = (_loc_8 + 1) + _loc_9 * (param4 + 1) + _loc_7;
                    var _loc_20:* = _loc_6 + 1;
                    indexVector[_loc_20] = _loc_8 + (_loc_9 + 1) * (param4 + 1) + _loc_7;
                    _loc_8 = _loc_8 + 1;
                }
                _loc_9 = _loc_9 + 1;
            }
            return;
        }// end function

        public function get depth() : Number
        {
            return this._depth;
        }// end function

        public function get segments() : uint
        {
            return this._segments;
        }// end function

        public function get height() : Number
        {
            return this._height;
        }// end function

        public function get width() : Number
        {
            return this._width;
        }// end function

    }
}
